from django.shortcuts import render,redirect
from django.urls import reverse
from common.models import TUser
from common.models import *

# 首页
def index(request):
     return render(request, 'myapp/index/index.html')

# 登录表单
def login(request):
    return render(request, 'myapp/index/login.html')

# 执行登录
def dologin(request):
    try:
        user = TUser.objects.get(uname=request.POST['user_name'])
        if user.utype=='管理员':
            if (user.upassword==request.POST['user_password']):
                request.session['adminuser'] = user.toDict()
                return redirect(reverse('myapp_index'))
            else:
                context = {'info': "密码错误！"}
        else :context = {'info':'您没有权限！'}
    except:
        context = {'info': "账号不存在!"}   
    print(context)
    return render(request, "myapp/index/login.html", context)
    
 



# 退出
def logout(request):
    pass
